import { message } from 'antd';

// 导出一个函数，用于删除部门
export const deleteDept = async (deptId, refreshData) => {
  const url = `http://1.94.134.166:8805/dept/${deptId}`;
  const authorization = localStorage.getItem('Authorization');

  try {
    const response = await fetch(url, {
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json',
        Authorization: authorization,
      },
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const res = await response.json();
    const { code = 0 } = res;
    if (code === 0) {
      message.success("删除成功");
      refreshData(); // 调用传入的refreshData函数来刷新数据
    } else {
      message.error("删除失败");
    }
  } catch (error) {
    console.error('Error deleting department:', error);
    message.error("删除出错");
  }
};
